﻿using Newtonsoft.Json;

namespace Common.EventBus.EventBusRabbitMQ
{
    public abstract class BaseQueueHandler<T> : IQueueHandler where T : IQueueEvent
    {
        public async Task Handler(string message)
        {
            if (!string.IsNullOrWhiteSpace(message))
            {
                var eventData = JsonConvert.DeserializeObject<T>(message);
                await Handler(eventData);
            }
        }

        public abstract Task Handler(T e);
    }
    public abstract class BaseQueueSyncHandler<T> : IQueueSyncHandler where T : IQueueEvent
    {
        public void Handler(string message)
        {
            if (!string.IsNullOrWhiteSpace(message))
            {
                var eventData = JsonConvert.DeserializeObject<T>(message);
                Handler(eventData);
            }
        }

        public abstract void Handler(T e);
    }
}